class LoginController {
    constructor($rootScope, $scope, $state, $cookieStore, $timeout, ngDialog, dialogService, UserService){
        
        var vm = this;

        vm.$rootScope    = $rootScope;
        vm.$state        = $state;
        vm.$cookieStore  = $cookieStore;
        vm.$timeout      = $timeout;
        vm.ngDialog      = ngDialog;
        vm.dialogService = dialogService;
        vm.UserService   = UserService;

        // 初始化表单数据
        vm.user = {
            username: '',
            password: '',
            unCheck: false
        }
    }

    // 提交表单
    submitForm(isValid) {

        var vm = this;

        // 验证失败
        if (!isValid) {
            vm.dialogService.error('用户名或密码错误');
        }

        // 验证成功
        if (isValid) {


                // 提示用户登录成功
                vm.dialogService.success('登录成功');

                // 延迟1.5秒后, 关闭模态框并跳转路由至赛事机构列表页面
                vm.$timeout(function() {
                   vm.ngDialog.close();
                   vm.$state.go('sdk.index')

                    // 判断是否存在前一个页面地址, 是则跳转至并删除缓存, 否则跳转至机构列表页
                    // if (vm.$cookieStore.get('prevPage')) {
                    //     window.location.href = vm.$cookieStore.get('prevPage');
                    //     vm.$cookieStore.remove('prevPage');
                    // } else {
                    //     vm.$state.go('dashboard.companylist')
                    // }
                       
                }, 1500);

        }

        return false;
    }
}

LoginController.$inject = ['$rootScope', '$scope', '$state', '$cookieStore', '$timeout', 'ngDialog', 'dialogService', 'UserService']; 

export default LoginController;